<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[{name: 'box-base',title: '基础信息'},{name: 'box-info',title: '分类信息'}]"
      />
    </div>

    <!--表单区域-->
    <div  class="form-right" ref="formRight">
      <customForm
        :data="form"
        :rules="propRules"
        ref="editForm"
        :disabled="propReadonly"
        :label-width="120"
      >
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem
            label="品类名称"
            name="categoryName"
            :parent="_self"
            :form="form"
            help="自动生成"
          />
          <customFormItem
            label="品类代码"
            name="code"
            :parent="_self"
            :form="form"
            help="自动生成"
            disabled
          />
          <customFormItem
           label="父级品类"
           name="parentName"
           :parent="_self"
           :form="form"
           :readonly="true"
           :showSelectIcon="true"
           @focus="$refs.tableDrawerCategory.show()"
          />
          <customFormItem
            label="外网代码"
            name="mscmCode"
            :parent="_self"
            :form="form"
            disabled
          />
          <customFormItem
            label="HRP代码"
            name="hrpCode"
            :parent="_self"
            :form="form"
            disabled
          />
          <div id="box-info" class="box-title">分类信息</div>
          <customFormItem
            label="国家分类代码"
            name="countryCode"
            :parent="_self"
            :form="form"
          />
          <customFormItem
            label="国家分类名称"
            name="countryName"
            :parent="_self"
            :form="form"
          />
          <customFormItem
            label="统计分类院内代码"
            name="queryCode"
            :parent="_self"
            :form="form"
          />
          <customFormItem
            label="通用分类院内代码"
            name="commonCode"
            :parent="_self"
            :form="form"
          />
          <customFormItem
            label="通用分类院内名称"
            name="commonName"
            :parent="_self"
            :form="form"
          />
        </template>
      </customForm>
    </div>
    <!--品类选择-->
    <tableDrawer ref="tableDrawerCategory" refName="tableDrawerCategory" @confirm="tableDrawerConfirm" :viewKey="constCommon.viewKeySelect.matrCategory"/>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {}
    }
  },
  methods: {
    //下拉列表选择后
    tableDrawerConfirm(row) {
      this.$set(this.form, 'parentId', row.id)
      this.$set(this.form, 'parentName', row.categoryName)
      this.$set(this.form, 'parentId', row.id)
      this.$set(this.propInitData, 'label', row.categoryName)
    }
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.form = this.propCurrentRow
        console.log('this.form =====', this.form)
        // 新增时需要填写父级机构的id和名称
        if (!this.form.id && initData) {
          this.$set(this.form, 'parentId', initData.id)
        }
        this.$set(this.form, 'parentId', initData.id)
        this.$set(this.form, 'parentId', initData.id)
        this.$set(this.form, 'parentName', initData.label)

        // 设置switch 元素默认值
        this.$set(this.form, 'flagDefault', this.form.flagDefault == undefined ? false : this.form.flagDefault)

        // 设置switch 元素默认值
      },
      afterSave: () => {
        this.utils.refreshRefs(this)
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      }
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object
  },
  components: {
    customAnchor
  },
  computed: {}
}
</script>

<style lang="scss" scoped>
  .container {
    width: 100%;
    height: 100%;
  }
</style>
